<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<%@include file="../../common/include-header.jsp" %>
<body>
<div class="form-content">
    <form id="form-exam-add" class="form-horizontal">
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>考试标题：</label>
                    <div class="col-sm-8">
                        <input name="title" autocomplete="off" placeholder="请输入标题" class="form-control" type="text"
                               required
                               maxlength="30" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>开考时间：</label>
                    <div class="col-sm-8">
                        <input type="datetime-local" id="examStartDate" placeholder="开始时间" class="form-control"
                               name="examTime"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label"><span style="color: red; ">*</span>考试班级：</label>
                    <div class="col-xs-4">
                        <span>S1 : </span>
                        <c:forEach items="${classes1}" var="aClass">
                            &nbsp; &nbsp;
                            <label>
                                <input type="checkbox" name="classId" value="${aClass.id}"> &nbsp;<span>${aClass.name}</span>
                            </label>
                            &nbsp; &nbsp;
                        </c:forEach>                        <hr/>
                        <span> S2 : </span>
                        <c:forEach items="${classes2}" var="aClass">
                            &nbsp; &nbsp;
                            <label>
                                <input type="checkbox" name="classId" value="${aClass.id}"> &nbsp;<span>${aClass.name}</span>
                            </label>
                            &nbsp; &nbsp;
                        </c:forEach>                        <hr/>
                        <span>Y2 : </span>
                        <c:forEach items="${classes3}" var="aClass">
                            &nbsp; &nbsp;
                            <label>
                                <input type="checkbox" name="classId" value="${aClass.id}"> &nbsp;<span>${aClass.name}</span>
                            </label>
                            &nbsp; &nbsp;
                        </c:forEach>
                    </div>
                </div>
            </div>
        </div>
    </form>
<%--    <h4 class="form-header h4">指定试卷的题目</h4>--%>
    <div class="row">
        <div class="col-sm-12  ">
            <table id="bootstrap-table1" data-mobile-responsive="true"></table>
        </div>
    </div>
<%--    <div class="container-div">--%>
<%--        <div class="row">--%>
<%--            <div class="col-sm-12 search-collapse">--%>
<%--                <form id="role-form">--%>
<%--                    <div class="select-list">--%>
<%--                    </div>--%>
<%--                </form>--%>
<%--            </div>--%>

            <div class="btn-group-sm" id="toolbar" role="group">
                <%--<a class="btn btn-success" onclick="$.operate.add()">
                    <i class="fa fa-plus"></i> 添加试题
                </a>--%>
                <span class="text-info"> 请直接选择需要添加的试卷</span>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <%@include file="../../common/include-footer.jsp" %>
    <script>
        $(function () {
            var servicesArray = data.split(",");
            $("input[type=checkbox][name=btSelectItem]").each(function (i, e) {
                for (var i = 0; i < servicesArray.length; i++) {
                    if ($(this).val() == servicesArray[i]) {
                        $(this).iCheck('check');
                    }
                }
            });

        });
        var data = "";
        var prefix = "/testPaper";
        $(function () {
            var options = {
                url: prefix + "/list",
                sortName: "asc",
                height: 500,
                modalName: "试卷",
                columns: [{
                    radio: true
                },
                    {
                        field: 'id',
                        title: '试卷编号'
                    },
                    {
                        field: 'name',
                        title: '试卷名'
                    },
                    {
                        field: 'courseName',
                        title: '科目名称'
                    },
                    {
                        field: 'amount',
                        title: '题目数量'
                    },
                    {
                        field: 'duration',
                        title: '试卷持续时间（分钟）',
                        sortable: true
                    },
                    {
                        field: 'teacherName',
                        title: '出卷人',
                        sortable: true
                    },
                    {
                        field: 'createTime',
                        title: '创建时间',
                        sortable: true,
                        formatter:function(val, item, rowIndex){
                            var date = new Date(val);
                            var YY = date.getFullYear() + '-';
                            var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                            var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
                            var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
                            var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
                            var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
                            return YY + MM + DD +" "+hh + mm + ss;
                        }
                    }]
            };
            $.table.init(options);
        });

        function checksubmit() {
            var title = $("input[name=title]").val();
            var examTime = $("input[name=examTime]").val();

            var classId = [];
            $('input[name=classId]:checked').each(function () {
               classId.push($(this).val());
            });

            var testPaperId = $("tr.selected").find("td").eq(1).text();

            var date = new Date();
            var date2 = new Date(examTime);

            if (title == "") {layer.msg("请输入标题");return false;}
            if (examTime == "") {layer.msg("请选择开考日期");return false;}
            if (date > date2 == true) {layer.msg("不能选择之前的日期作为开考日期");return false;}
            if (classId == "") {layer.msg("请选择考试班级");return false;}
            if (testPaperId == "") {layer.msg("请指定考试试卷");return false;}

            examTime = new Date(examTime);

            var YY = examTime.getFullYear() + '-';
            var MM = (examTime.getMonth() + 1 < 10 ? '0' + (examTime.getMonth() + 1) : examTime.getMonth() + 1) + '-';
            var DD = (examTime.getDate() < 10 ? '0' + (examTime.getDate()) : examTime.getDate());
            var hh = (examTime.getHours() < 10 ? '0' + examTime.getHours() : examTime.getHours()) + ':';
            var mm = (examTime.getMinutes() < 10 ? '0' + examTime.getMinutes() : examTime.getMinutes()) + ':';
            var ss = (examTime.getSeconds() < 10 ? '0' + examTime.getSeconds() : examTime.getSeconds());
            examTime =  YY + MM + DD +" "+hh + mm + ss;

            data = {
                "title": title, "examTime": examTime, "classId": classId, "testPaperId": testPaperId};
            return true;
        }

        function submitHandler() {
            if (!checksubmit()) {
                return;
            }
            $.operate.save('${pageContext.request.contextPath}/exam/addExam', data);
        }
        
        function checkboxClick (event) {

        }
    </script>

</div>

<%@include file="../../common/include-footer.jsp" %>

<script src="/static/plugin/select/select2.js"></script>

</body>
</html>
